import type { XtxGuessInstance } from '@/types/component'
import { ref } from 'vue'

// 防抖函数
const debounce = (fn: any) => {
  let t: number | null = null
  return () => {
    if (t) {
      clearTimeout(t)
    }
    t = setTimeout(() => {
      fn()
    }, 1000)
  }
}

export const useGuessList = () => {
  const guessRef = ref<XtxGuessInstance>()

  const onScrollToLower = () => {
    debounce(guessRef.value?.getMore)()
  }

  return {
    guessRef,
    onScrollToLower,
  }
}
